import axios from './libs/axios/index.js';

// create axios instance
const request = axios.create({
    headers: {
        'Content-Type': 'application/json; charset=utf8',
    },
    baseUrl: 'http://localhost:19098/nest-auth/api/v1/',
    timeout: 10000 * 10,
});

/**
 * 发起拦截
 */
request.interceptors.request.use(
    (config) => {
        console.log('---------请求拦截----------')
        return config;
    },
    (err) => {
        console.log('---------请求拦截Error----------')
        console.log(err);
    },
);

/**
 * 响应拦截
 */
request.interceptors.response.use(
    (data) => {
        console.log('-------响应拦截-----');
        return Promise.resolve(data);
    },
    (err) => {
        console.log('-------响应拦截Error-----');
        return Promise.reject(err);
    },
);

const test = request.post(
    'auth/login',
    {
        userName: 'admin',
        password: '123456',
    },
    {
        headers: {
            test: '111',
        },
    },
);
test.then(data => {
    console.log(data)
}).catch(err => {
    console.log(err)
})
